package com.huawei.esdk.tp.common.local.authentication;

import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPFault;
import javax.xml.ws.Holder;
import javax.xml.ws.soap.SOAPFaultException;

import com.huawei.esdk.tp.common.local.MyFaultException;
import com.huawei.esdk.tp.common.local.impl.autogen.TPCommon;

public class TPCommonImpl implements TPCommon {
	public static int loginResult = 0;
	public static int authenticateResult = 0;
	public static int logoutResult = 0;
	public static int keepAliveResult = 0;
	
	public static boolean throwException = false;
	public static int exceptionCode = 0; 
	
	private SOAPFaultException getSOAPFaultException(){
		SOAPFaultException se = null;
		try {
			SOAPFault fault = new MyFaultException();
			fault.setFaultCode(String.valueOf(exceptionCode));
			se = new SOAPFaultException(fault);
		} catch (SOAPException e) {
			e.printStackTrace();
		}
		return se;
	}
	
	@Override
	public Integer logout() {
		if (throwException) {
			throw getSOAPFaultException();
		}
		return logoutResult;
	}
	@Override
	public Integer keepAlive() {
		if (throwException) {
			throw getSOAPFaultException();
		}
		return keepAliveResult;
	}
	@Override
	public Integer authenticate(byte[] encryptPassword) {
		if (throwException) {
			throw getSOAPFaultException();
		}
		return authenticateResult;
	}
	@Override
	public void loginRequest(String userName, String clientType,
			Integer version, Holder<Integer> resultCode,
			Holder<byte[]> randomSequence, Holder<String> hashType) {
		resultCode.value = loginResult;
	}


}
